/***
 * 公共处理响应结果
 * @param promiseFunc { Promise }
 * @param msg { String }
 * @param isReturn { Boolean }
 */
const globalSendResult = ({promiseFunc, msg, isReturn = true,response, errMsg = '', countTotal = false, queryData = {},Services = {} }) => {
    promiseFunc.then( async result => {
        const code = result ? 1 : 0
        response.send({
            code,
            data: isReturn ? result : null,
            success: true,
            msg: result ?`${ msg }成功` || '操作成功' : errMsg,
            total: countTotal ? await (Services.queryCount(queryData)) : null
        })
    }).catch(e => {
        response.send({
            code: 0,
            success: false,
            msg: e || `${ msg }失败` || '请求服务区错误'
        })
    })
}

module.exports = globalSendResult
